/**
 * appRain v 0.1.x
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Team. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */

jQuery(document).ready(function() {

	var row_id;
	var deletemessage = "Are you sure to Delete?\n\nThere is currently a request to delete data from the sytem. You may can not undone.\n\nPress OK to continue, or Cancel to stay on same position.";

	if(jQuery('#checkall'))
	{
		jQuery('._deletebtn').live('click', function(e) {

			var myJSONtext = jQuery(this).attr('id');
			var opts = eval('(' + myJSONtext + ')');

			var ids = "";
			jQuery('.checkrow').each(function(key,obj){
				if(jQuery(obj).attr('checked'))
				{
					ids += ((ids=="")?"":",") + jQuery(obj).val();
				}
			});

			if(ids!="")
			{
				if(confirm(deletemessage))
				{
					jQuery.ajax({
						url: siteInfo.baseUrl + "/common/deletegroup/" + opts.mode,
						 type: "POST",
						data: ({'ids':'{' + ids + '}'}),
						context: document.body,
						success: function(){
						  window.location="";
						}
					});
				}
			}
		});
	}

	jQuery('.link_delete').live('click', function(e) {

		var model = jQuery(this).attr('title').split('_')[0];
		var id = jQuery(this).attr('title').split('_')[1];
		row_id = jQuery(this).closest("tr").get("id");

		/*var highlight = new Fx.Morph(row_id, {
		duration: 1500,
		link: 'cancel',
		transition: 'quad:out'
		});*/

		var orginal_color = jQuery('#'+row_id).css('background-color');

		/*highlight.start({
				backgroundColor: ['#fff36f', '#FFFF1A' ],
				opacity: [.5, 1]
		});*/


		if(confirm(deletemessage))
		{
			jQuery.get(siteInfo.baseUrl + "/common/delete_row/" +  model + "/" + id, function(data) {
				window.location="";
			  });


			//req.send({url:base + "/common/delete_row/" +  model + "/" + id });
		}
		else
		{
			/*highlight.start({
				backgroundColor: ['#FFFF1A',orginal_color ],
				opacity: [.5, 1]
			});*/

		}
	});

	//if(jQuerychk(jQuery('.delete_informationset_file')))
	//{
		jQuery('.delete_informationset_file').live('click', function (e) {
			var obj = jQuery(this).closest('span');
			jQuery(this).attr('src') = siteInfo.baseUrl + '/images/loading.gif';
			jQuery(this).css('margin-left','5px');

			jQuery.get(siteInfo.baseUrl + "/common/delete_row/delete_informationset_file/" + jQuery(this).attr('id'), function(data) {
				//window.location="";
			  });

			/*var req = new Request({url:base,
				onSuccess: function(txt) {
					obj.setStyle('display','none');
				},
				onFailure: function() {
					alert("Sorry... Commond could not execute");
				}
			});
			req.send({url:base + "/common/delete_row/delete_informationset_file/" + this.id });*/
		});
	//}
});